package com.qffx.moviebase.view.classify;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.qffx.moviebase.R;
import com.qffx.moviebase.adapter.classify.SpeacialMoreAdapter;
import com.qffx.moviebase.bean.classify.SpeacialMoreEntity;
import com.qffx.moviebase.utils.retrofit.HttpService;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ClassifySpeacialMoreActivity extends AppCompatActivity implements Callback<SpeacialMoreEntity> {
    private SpeacialMoreAdapter adapter;
    private List<SpeacialMoreEntity.TopicListBean> list = new ArrayList<>();
    private RecyclerView recycler;
    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_classify_speacial_more);
        init();
    }

    private void init() {
        recycler = (RecyclerView) findViewById(R.id.special_all_recycler);
        recycler.setLayoutManager(new GridLayoutManager(this, 2, LinearLayoutManager.VERTICAL, false));
        adapter = new SpeacialMoreAdapter(list, this);
        recycler.setAdapter(adapter);
        tv= (TextView) findViewById(R.id.speacial_more_tvback);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        HttpService service = new Retrofit.Builder()
                .baseUrl("http://www.baidu.com")
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(HttpService.class);
        service.getspecialMore().enqueue(this);

    }

    @Override
    public void onResponse(Call<SpeacialMoreEntity> call, Response<SpeacialMoreEntity> response) {
        list.addAll(response.body().getTopicList());
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onFailure(Call<SpeacialMoreEntity> call, Throwable t) {


    }
}
